<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.HashMap" %>
<%@ page isELIgnored="false" contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt"  prefix="fmt"%>
<html>
<head>
    <title>遍历demo</title>
    <style>
        div{
            width:300px;
            height:100px;
            position: absolute;
            top:50%;
            left:50%;
            margin-top: -50px ;
            margin-left:-150px;
        }
        td{
            border-width: medium;
            border-style: double;
            border-color: red;
            width: 100px;
        }
    </style>
</head>
<body>
<%
    ArrayList<String> header = new ArrayList<>();
    header.add("1");
    header.add("2");

    ArrayList<String> columnName = new ArrayList<>();
    columnName.add("1");
    columnName.add("2");

    Map<String, Map<String, String>> cellMap = new HashMap<String, Map<String, String>>();
    HashMap<String, String> a = new HashMap<>();
    a.put("id","a");
    a.put("color","red");
    cellMap.put("1·1", a);
    HashMap<String, String> b = new HashMap<>();
    b.put("id","b");
    b.put("color","");
    cellMap.put("1·2", b);
    HashMap<String, String> c = new HashMap<>();
    c.put("id","c");
    c.put("color","");
    cellMap.put("2·1", c);
    HashMap<String, String> d = new HashMap<>();
    d.put("id","d");
    d.put("color","red");
    cellMap.put("2·2", d);
%>
<div>
    <button onclick="window.history.back(-1)">返回</button>
    <button onclick="window.location.href='${pageContext.request.contextPath}/login/toLogout'">退出</button>
    <table>
        <tr>
            <c:forEach var="head" items="<%=header %>" varStatus="status">
                <c:if test="${status.index == 0}">
                <th>
                    财报
                </th>
                </c:if>
                    <th>
                            ${head}
                    </th>
            </c:forEach>
        </tr>
        <c:forEach var="column" items="<%=columnName %>">
            <tr>
                <c:forEach var="head" items="<%=header %>" varStatus="status">
                    <c:if test="${status.index == 0}">
                        <td>
                                ${column}
                        </td>
                    </c:if>
                    <td>
                        <%
                            String col = (String)pageContext.findAttribute("column");
                            String he = (String)pageContext.findAttribute("head");
                            Map<String, String> map = cellMap.get(col + "·" + he);
                            String red = "red";
                            String id = map.get("id");
                            String color = map.get("color");
                        %>
                        <c:choose>
                            <c:when test="<%= color == red %>">
                                <span style="color: red">
                                    <%=id%>
                                </span>
                            </c:when>
                            <c:otherwise>
                                <%=id%>
                            </c:otherwise>
                        </c:choose>

                    </td>
                </c:forEach>
            </tr>
        </c:forEach>
    </table>
</div>


</body>
</html>
